package com.yuexi.web;

import com.yuexi.anotation.AutoHead;
import com.yuexi.anotation.AutoPage;
import com.yuexi.bill.api.BillService;
import com.yuexi.bill.cqe.BillQuery;
import com.yuexi.bill.cqe.PayBillCmd;
import com.yuexi.bill.dto.BillDTO;
import com.zenx.dto.Response;
import com.zenx.dto.SingleResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author jie
 * @date 2023/4/6 -16:06
 */
@RequestMapping("/bill")
@Api(tags = "账单")
@RestController
public class BillController {

    @Autowired
    private BillService service;

    @AutoPage
    @ApiOperation("列表--分页")
    @PostMapping("/page")
    public SingleResponse<List<BillDTO>> page(@Validated @RequestBody BillQuery query) {
        return SingleResponse.success(service.list(query));
    }

    @AutoHead
    @ApiOperation("结算")
    @PostMapping("pay")
    public Response payBill(@Validated @RequestBody PayBillCmd cmd) {
        service.payBill(cmd);
        return Response.success();
    }
}
